local boqibu = fk.CreateSkill {
  name = "boqibu",
}

Fk:loadTranslationTable{
  ["boqibu"] = "七步",
  [":boqibu"] = "当你造成或受到伤害后，你可以摸至多7张牌。若如此做，此技能失效直到你累计使用了等量的牌。",

  ["#boqibu-draw"] = "七步：你可以摸至多7张牌，此技能失效直到你使用等量张牌",
  ["@boqibu"] = "七步",

  ["$boqibu1"] = "借君一壶酒，七步亦成诗。",
  ["$boqibu2"] = "疑有暗香来，几度梅花开。",
}

local spec = {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(boqibu.name) and player:getMark("@boqibu") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    for i = 1, 7, 1 do
      table.insert(choices, tostring(i))
    end
    table.insert(choices, "Cancel")
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = boqibu.name,
      prompt = "#boqibu-draw:::7",
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = tonumber(choice)})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = event:getCostData(self).choice
    room:setPlayerMark(player, "@boqibu", n)
    room:invalidateSkill(player, boqibu.name)
    player:drawCards(n, boqibu.name)
  end,
}

boqibu:addEffect(fk.Damage, spec)
boqibu:addEffect(fk.Damaged, spec)

boqibu:addEffect(fk.CardUsing, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(boqibu.name, true) and player:getMark("@boqibu") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@boqibu")
    if player:getMark("@boqibu") < 1 then
      room:validateSkill(player, boqibu.name)
    end
  end,
})

boqibu:addLoseEffect(function (self, player, is_death)
  local room = player.room
  room:validateSkill(player, boqibu.name)
  room:setPlayerMark(player, "@boqibu", 0)
end)

return boqibu
